package com.briup.oagg.facade.web.controller.dataset;

import com.briup.oagg.facade.web.vm.page.Page;
import com.briup.framework.utils.web.Response;
import com.briup.oagg.facade.service.dateset.IBasinService;
import com.briup.oagg.facade.web.vm.dataset.BasinAddVM;
import com.briup.oagg.facade.web.vm.dataset.BasinUpdateVM;
import com.briup.oagg.facade.web.vm.dataset.BasinVM;
import com.briup.oagg.facade.web.vm.dataset.TreeInfoVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 盆地信息业务前端控制器
 *
 * @author briup
 */
@Api(tags = "1.1.盆地管理服务")
@RestController
@RequestMapping("/basin")
public class BasinController {
    @Autowired
    private IBasinService service;

    @ApiOperation(value = "新增盆地", notes = "通过输入名称和特征描述信息保存信息。输入信息都必填。名称不能重复。")
    @PostMapping
    public Response<String> insertBasin(@RequestBody BasinAddVM vm) {
        service.addBasin(vm);
        return Response.success();
    }

    @ApiOperation(value = "修改盆地", notes = "通过输入盆地的ID，修改盆地信息，而且只能修改盆地的描述信息")
    @PutMapping
    public Response<String> updateBasinById(@RequestBody BasinUpdateVM vm) {
        service.updateBasin(vm);
        return Response.success();
    }

    @ApiOperation(value = "查询盆地总数")
    @GetMapping("/count")
    public Response<Integer> count() {
        Integer count = service.count();
        return Response.success(count);
    }

    @ApiOperation(value = "分页查询盆地", notes = "分页查询盆地(根据每页大小和当前页分页显示信息列表。)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页码",defaultValue = "1",required = true,dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "每页大小",defaultValue = "5",required = true,dataTypeClass = Integer.class)
    })
    @GetMapping("/page")
    public Response<Page<BasinVM>> findByPage(Integer pageNum, Integer pageSize) {
        Page<BasinVM> page = service.findByPage(pageNum, pageSize);
        return Response.success(page);
    }

    @ApiOperation(value = "查询地址信息树", notes = "查询地址信息树")
    @GetMapping("/tree")
    public Response<List<TreeInfoVM>> findByTree() {
        List<TreeInfoVM> list = service.findByTree();
        return Response.success(list);
    }

    @ApiOperation(value = "删除盆地", notes = "删除盆地（根据盆地编号删除盆地信息及其对应的区带、圈闭和油气藏信息）")
    @ApiImplicitParam(name = "basinId", value = "盆地ID")
    @DeleteMapping("/{basinId}")
    public Response deleteById(@PathVariable String basinId) {
        service.deleteById(basinId);
        return Response.success();
    }
}
